<?php
	class Courseware extends MY_controller{
		function __construct(){
			parent::__construct();
		}

		function index($school_id = 'all', $name = 0, $limit = 0 ){
			//获取网校
			$this->load->model('Schools');
			$schools = $this->Schools->get_school_all();
			$this->smarty->assign("schools", $schools);

			
			if($_POST){
				$post_data = $this->input->post();
				if(!empty($post_data['school_id'])){
					$school_id = $post_data['school_id'];
				}
				if(!empty($post_data['name'])){
					$name = $post_data['name'];
				}
			}
			$conditions['school_id'] = $school_id;
			$conditions['name'] = $name;
			$this->load->model("Courses");
			$courses = $this->Courses->get_class_course($limit, $this->offset, $conditions);
			// print_r($courses);
			$this->load->library('pagination');
			$page_config['base_url'] = '/courseware/index/' . $school_id . '/' . $name;
			$page_config['total_rows'] = $courses['total_count'];
			$page_config['per_page'] = $this->offset;
			$page_config['uri_segment'] = 5;
			$this->pagination->initialize($page_config);
			$pagination = $this->pagination->create_links();
			$this->smarty->assign("pagination", $pagination);
			$this->smarty->assign("conditions", $conditions);
			$this->smarty->assign("action", '课件管理');
			$this->smarty->assign("courses", $courses);
			$this->smarty->display("courseware/index.html");
		}

		function delete($ids = 0){
			if($_POST){
				$ids = $this->input->post('ids');
			}else{
				$ids = (array) $ids;
			}
			delete_data($ids, "o2o_class_courses");
			if($this->db->affected_rows() > 0){
				show_message($_SERVER['HTTP_REFERER'], "删除成功");
			}else{
				show_message($_SERVER['HTTP_REFERER'], "删除失败，请重试！");
			}
		}
	}